package com.longe.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @DefaultProperties : 指定此接口中公共的熔断设置
 *      如果过在@DefaultProperties指定了公共的降级方法
 *      在@HystrixCommand不需要指定fallbackMethod了
 */
@DefaultProperties(defaultFallback = "defaultConsumerFallBack")
@RestController
public class ConsumerTwoController {

    @Autowired
    private RestTemplate restTemplate;
    
    @HystrixCommand//无需指定fallbackMethod
    @RequestMapping("consumer/1")
    public String consumer1(){
        String result = restTemplate.getForObject("http://provider-server/provider", String.class);
        return result;
    }

    @HystrixCommand//无需指定fallbackMethod
    @RequestMapping("consumer/2")
    public String consumer2(){
        String result = restTemplate.getForObject("http://provider-server/provider", String.class);
        return result;
    }

    /**
     * 指定统一的降级方法
     * 参数 : 没有参数
     */
    public String defaultConsumerFallBack() {
        return "大兄弟,触发[统一]降级方法了......";
    }
}